package com.qf.myrbac.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.qf.myrbac.annotation.DataFilter;
import com.qf.myrbac.sys.entity.SysDept;
import com.qf.myrbac.sys.dao.SysDeptDao;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.myrbac.sys.service.SysDeptService;
import com.qf.myrbac.utils.Constants;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 部门管理 服务实现类
 * </p>
 *
 * @author 徐英海
 * @since 2022-10-27
 */
@Service
public class SysDeptServiceImpl extends ServiceImpl<SysDeptDao, SysDept> implements SysDeptService {
    @Transactional(propagation = Propagation.SUPPORTS)
    @DataFilter(dataField = "dept_id")
    @Override
    public List<SysDept> queryDeptByMap(Map<String, String> params) {
        String dataFilter = params.get(Constants.DATA_FILETER);
        QueryWrapper<SysDept> deptQueryWrapper = new QueryWrapper<>();
        deptQueryWrapper.apply(StringUtils.isNotBlank(dataFilter), dataFilter);
        return this.list(deptQueryWrapper);
    }
}
